package com.dz.goods.controller;

import com.dz.common.base.BaseApiService;
import com.dz.common.base.BasePageResultsVO;
import com.dz.common.base.ResponseBase;
import com.dz.goods.domain.entity.Spec;
import com.dz.goods.domain.vo.SpecParamsVO;
import com.dz.goods.domain.vo.SpecResultsVO;
import com.dz.goods.service.SpecService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods/spec")
@Api(tags = "规格管理")
public class SpecController extends BaseApiService {

    @Autowired
    private SpecService specService;

    @GetMapping("/get_spec_list")
    @ApiOperation(value = "条件查询规格")
    public ResponseBase getAlbumList(SpecParamsVO vo) throws Exception {
        BasePageResultsVO<SpecResultsVO> specList = specService.getSpecList(vo);
        return setResultSuccess(specList) ;
    }
    @PostMapping("/add")
    @ApiOperation(value = "添加规格")
    public ResponseBase add(@RequestBody Spec spec) throws Exception {
        Spec add = specService.add(spec);
        return setResultSuccess(add) ;
    }
    @PostMapping("/edit")
    @ApiOperation(value = "更新规格")
    public ResponseBase edit(@RequestBody Spec spec) throws Exception {
        Spec edit = specService.edit(spec);
        return setResultSuccess(edit) ;
    }
    @GetMapping("/get_by_id")
    @ApiOperation(value = "根据id查询规格")
    public ResponseBase getById(Long specId) throws Exception {
        Spec spec = specService.findById(specId);
        return setResultSuccess(spec) ;
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除规格")
    public ResponseBase delete(Long specId) throws Exception {
        specService.delete(specId);
        return setResultSuccess();
    }
    @GetMapping("/get_by_category_id")
    @ApiOperation(value = "根据分类id查询规格")
    public ResponseBase getByCategoryId(Long categoryid) throws Exception {
        List<SpecResultsVO> specResultsVOS = specService.findByCategoryId(categoryid);
        return setResultSuccess(specResultsVOS);
    }
}